package Math;

public class _326_PowerofThree {
    //solution 1:using loop
    public boolean isPowerOfThree_0(int n) {
        while (n >= 3) {
            int res = n%3;
            if (res != 0) {
                return false;
            }
            n /= 3;
        }
        return n == 1;
    }

    //solution 2:faster
    public boolean isPowerOfThree(int n) {
        if (n == 0) {
            return false;
        }
        while (n % 3 == 0) {
            n /= 3;
        }
        return (n == 1);
    }

}
